package com.song.service.topic;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.song.common.Result;
import com.song.dao.topic.TopicDao;
import com.song.entity.topic.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("topicService")
public class TopicServiceImpl extends ServiceImpl<TopicDao,Topic> implements TopicService {

    @Autowired
    private TopicDao topicDao;

    @Override
    public Result<List<Topic>> selectTopicList(Topic topic, String startTime, String endTime, int pageNum, int pageSize) {
        Result<List<Topic>> result = new Result<>();
        PageHelper.startPage(pageNum,pageSize);

        Map<String,Object> map = new HashMap<>();
        map.put("roleName",topic.getTopicName());
        map.put("startTime",startTime);
        map.put("endTime",endTime);
        map.put("status",topic.getStatus());

        List<Topic> topics = topicDao.selectTopicList(map);
        PageInfo<Topic> pageInfo = new PageInfo<>(topics);
        result.setCode(0);
        result.setCount((int)pageInfo.getTotal());
        result.setData(topics);
        return result;
    }
}
